package com.core.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.model.User;
import com.core.service.UserService;
 
@Controller
@RequestMapping(value = "/user")
public class UserController extends BaseController{
 
	@Autowired
	private UserService userService;
	
    @RequestMapping(value="/index")
    public String index(User user, Model model){
    	userService.insertUser(user);
        model.addAttribute("user", user);
        return "index";
    }
    
    @RequestMapping(value = "/loginView")
    public String loginView(){
    	return "loginView";
    }
     
    @RequestMapping(value = "/register")
    public String register(User user, Model model){
    	return "homePage";
    }
    
    @RequestMapping(value = "/test")
    public String test(){
    	userService.test();
    	return "homePage";
    }
    
    @RequestMapping(value = "loginTest")
    public String loginTest(User user, Model model){
    	Page<User> page = new Page<User>();
    	EntityWrapper<User> entityWrapper = new EntityWrapper<User>(user);
    	User u = userService.loginTest(user, page, entityWrapper);
    	System.out.println(u.getName());
    	return "homePage";
    }
    
}